package com.maxlen.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class StatusValueConstraintValidatorForLong implements ConstraintValidator<StatusValue, Long> {

    private Set<Long> valSet = new HashSet<>();

    @Override
    public void initialize(StatusValue constraintAnnotation) {
        int[] val = constraintAnnotation.val();
        for (int i : val) {
            valSet.add(new Long(i));
        }
    }

    @Override
    public boolean isValid(Long integer, ConstraintValidatorContext constraintValidatorContext) {
        if(integer == null){
            return true;
        }
        return valSet.contains(integer);
    }
}
